package com.foreknow.elmboot.mapper;

import com.foreknow.elmboot.po.DeliveryAddress;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface DeliveryAddressMapper {
    /**
     * 依据daId查询地址
     * @param daId
     * @return
     * @throws Exception
     */
    @Select("select * from deliveryaddress where daId=#{daId}")
    public DeliveryAddress queryAddressByDaId(Integer daId);

    /**
     * 依据userId查询地址
     * @param userId
     * @return
     * @throws Exception
     */
    @Select("select * from deliveryaddress where userId=#{userId}")
    public List<DeliveryAddress> queryAddressByUserId(String userId);

    /**
     * 添加地址
     * @param deliveryAddress
     * @return
     * @throws Exception
     */
    @Insert("insert into deliveryaddress(contactName,contactSex,contactTel,address,userId) values(#{contactName},#{contactSex},#{contactTel},#{address},#{userId})")
    public int addAddress(DeliveryAddress deliveryAddress);

    /**
     * 删除地址
     * @param daId
     * @return
     * @throws Exception
     */
    @Delete("delete from deliveryaddress where daId=#{daId}")
    public int deleteAddress(Integer daId);

    /**
     * 修改地址
     * @param deliveryAddress
     * @return
     * @throws Exception
     */
    @Update("update deliveryaddress set contactName=#{contactName},contactSex=#{contactSex},contactTel=#{contactTel},address=#{address} where daId=#{daId}")
    public int updateAddress(DeliveryAddress deliveryAddress);
}
